<template>
  <div class="mod-config">
    <basic-container>
      <el-form :inline="true" :model="dataForm" ref="searchForm">
        <el-row>
          <el-form-item>
            <el-input v-model="dataForm.cardNum" placeholder="请输入卡号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="dataForm.name" placeholder="请输入姓名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="dataForm.telPhone" placeholder="请输入手机号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="getDataList()">查询</el-button>
            <el-button icon="el-icon-delete" @click="searchReset">清空</el-button>
          </el-form-item>
        </el-row>
        <!-- <el-row>
           <el-button type="primary" icon="el-icon-plus" @click="openAddForm">新增</el-button>
         </el-row>-->
      </el-form>

      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column prop="registerConfigName" header-align="center" align="center" label="挂号项目"></el-table-column>
          <el-table-column prop="price" header-align="center" align="center" label="挂号费用"></el-table-column>
          <el-table-column prop="personName" header-align="center" align="center" label="姓名"></el-table-column>
          <el-table-column prop="cardNum" header-align="center" align="center" label="卡号"></el-table-column>
          <el-table-column prop="telPhone" header-align="center" align="center" label="电话号码"></el-table-column>
          <el-table-column prop="status" header-align="center" align="center" label="当前状态">
            <template slot-scope="scope">
              {{getRegisterStatusType(scope.row.status)}}
            </template>
          </el-table-column>
          <el-table-column header-align="center" align="center" label="操作">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.status==6" size="small" icon="el-icon-view" @click="checkDetail(scope.row)">查看</el-button>
              <el-button type="text" v-if="scope.row.status==2" size="small" icon="el-icon-edit" @click="checkDetail(scope.row)">预检</el-button>
              <el-button type="text" v-if="scope.row.status!=2&&scope.row.status!=6" size="small" icon="el-icon-edit"
                @click="checkDetail(scope.row)">就诊</el-button>
              <el-button type="text" v-if="scope.row.status==4" size="small" icon="el-icon-edit" @click="paymentHandle(scope.row.id,scope.row.chkDataId)">检查付费</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="checkdataVisible" ref="checkdata" @refreshDataList="getDataList"></table-form>
      <payment-form v-if="paymentVisible" ref="paymentDataForm" @refreshDataList="getDataList"></payment-form>
    </basic-container>
  </div>
</template>

<script>
  import { filterParams } from '@/util/tools'
  import { remote } from '@/api/admin/dict'
  import { fetchMatchingList, delMatchingObj } from '@/api/eims/cashier/payment'
  import { registerCenterForCheckPage } from '@/api/eims/cashier/register'

  import TableForm from './checkdata-form'
  import PaymentForm from './payment-form'


  import { mapGetters } from 'vuex'
  export default {
    data() {
      return {
        dataForm: {
          key: '',
          name: ''
        },
        dataList: [],
        registerTypeData: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        paymentVisible: false,
        checkdataVisible: false
      }
    },
    created() {
      remote('register_type').then(result => {
        this.registerTypeData = result.data.data
      })
      this.getDataList()
    },
    computed: {
      ...mapGetters(['permissions', 'bizData', 'userInfo'])
    },
    components: {
      PaymentForm,
      TableForm
    },
    methods: {
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.dataForm.deptId = this.userInfo.lessDeptId
        let params1 = {
          current: this.pageIndex,
          size: this.pageSize
        }
        let params2 = filterParams(this.dataForm)
        registerCenterForCheckPage(Object.assign(params1, params2)).then(response => {
          this.dataList = response.data.data.records
          this.totalPage = response.data.data.total
        })
        this.dataListLoading = false
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 搜索清空
      searchReset() {
        this.dataForm = {};
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      //  新增
      openAddForm() {
        this.paymentVisible = true
        this.$nextTick(() => {
          this.$refs.payment.init()
        })
      },
      // 删除
      deleteHandle(id) {
        this.$confirm('是否确认删除ID为' + id, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          return delMatchingObj(id)
        }).then(data => {
          this.$message.success('删除成功')
          this.getDataList()
        })
      },
      checkDetail(data) {
        this.checkdataVisible = true
        this.$nextTick(() => {
          if (data.chkDataId) { // 就诊信息
            this.$refs.checkdata.init(data.chkDataId, data.personId, 'chkdata')
          } else { // 预检信息
            this.$refs.checkdata.init(data.id, data.personId, 'register')
          }
        })
      },
      paymentHandle(id, chkDataId) {
        this.paymentVisible = true
        this.$nextTick(() => {
          this.$refs.paymentDataForm.init(id, chkDataId)
        })
      },
      getRegisterStatusType: function(value) {
        let obj = {};
        obj = this.registerTypeData.find((item) => {
          return item.value == value;
        });
        if(obj){
          return obj.label
        }
      }
    }
  }
</script>
